/**
 * Created by Admin on 2018/1/4.
 */
define(function (require, exports, module) {
    var AreaIpc = require("./areaIpc.js");
    var template = require("template");
    require("../seajs-init");
    var apiUrl = "", keyName, selfTitle, exportUrl, quotatitleD;

    $(function () {
        switch ($(".analysis-title").html()) {
            case "区域统计":
                apiUrl = "analysis/areaAnalysis";
                keyName = "areaName";
                selfTitle = "有效专利区域统计";
                exportUrl = "analysisexcel/areaAnalysis";
                quotatitleD = "统计本区域内下属区域的有效专利数量。";
                break;
            case "IPC分类统计":
                apiUrl = "analysis/ipcAnalysis";
                keyName = "ipcName";
                selfTitle = "有效专利IPC分类统计";
                exportUrl = "analysisexcel/ipcAnalysis";
                quotatitleD = "统计本区域内当前有效专利的IPC分布情况。"
                break;
            case "发明人统计":
                apiUrl = "analysis/inventorAnalysis";
                keyName = "inventorName";
                selfTitle = "有效专利发明人统计";
                exportUrl = "analysisexcel/inventorAnalysis";
                quotatitleD = "统计本区域内有效专利的发明人排名情况。";
                break;
        }
        AreaIpc.initTable(apiUrl, exportUrl, keyName, selfTitle, quotatitleD);

        $("body").on("click", ".ptmt-curpointer", function () {
            if ($(this).children(".up").length > 0) {
                $(this).children(".up").removeClass("up").addClass("down");
                $("[name=order]").val("asc");
                $("[name=sort]").val($(this).attr("data-sort"));
                AreaIpc.initTable(apiUrl, exportUrl, keyName, selfTitle, quotatitleD);
            } else {
                $(this).children(".down").removeClass("down").addClass("up");
                $("[name=order]").val("desc");
                $("[name=sort]").val($(this).attr("data-sort"));
                AreaIpc.initTable(apiUrl, exportUrl, keyName, selfTitle, quotatitleD);
            }
        })

        for (var i = 2; i <= 5; i++) {
            bindEvent(i)
        }

        function bindEvent(j) {
            $('#validptchart-tab').on('click', 'td', function () {
                var $self = $(this)
                var $parent = $self.parent('tr');
                if ($self.index() !== j) {
                    return
                }
                var areaId = $('td', $parent).eq(1).attr('data-area-id')
                switch (j) {
                    case 2:
                        localStorage.setItem("patHubTypeName", JSON.stringify(['发明公开', '发明授权']));
                        break;
                    case 3:
                        localStorage.setItem("patHubTypeName", JSON.stringify(['实用新型']));
                        break;
                    case 4:
                        localStorage.setItem("patHubTypeName", JSON.stringify(['外观设计']));
                        break;
                    case 5:
                        break;
                    default:
                        break;
                }
                if (areaId != -1) {
                    localStorage.setItem('areaId', areaId)
                }
                localStorage.setItem("lawState", JSON.stringify([1]));
                window.top.location.href = "/index.html#/analysis/patSearch.html";
            })
        }


    })

})